import { http } from "@/utils/http";
import type { ResultProps } from "@/api/user";

export interface DeviceProp {
  id: number;
  account_id: number;
  business_id: number;
  store_id: number;
  device_id: string;
  name: null | string;
  android_id: null | string;
  device_model: string;
  device_type: string;
  system_version: null | string;
  brand: null | string;
  province: string;
  city: string;
  device_status: number;
  run_status: number;
  delete_status: number;
  activation_time: Date;
  lock_time: null;
  update_time: Date;
  create_time: Date;
  store_name: string;
  deviceFormulaUseRecord: DeviceFormulaUseRecord | null;
  releaseRecord: ReleaseRecord | null;
  business_name: null;
  operator: null | string;
  phone: null | string;
  calibration_time: null;
  net_status: number | null;
}

export interface DeviceFormulaUseRecord {
  id: number;
  deviceId: string;
  version: number;
  name: string;
  useTime: Date;
}

export interface ReleaseRecord {
  releaseTime: Date;
  name: string;
  version: number;
}

export const deviceGetList = (data?: object) => {
  return http.request<ResultProps<DeviceProp[]>>(
    "post",
    "/device/getList",
    {
      data
    },
    {
      beforeResponseCallback() {}
    }
  );
};

export const updStoreId = (data?: object) => {
  return http.request<ResultProps<DeviceProp[]>>("post", "/device/updStoreId", {
    data
  });
};

export const deviceBindStoreId = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/device/bindStoreId", {
    data
  });
};

export const updDeviceStatus = (data?: object) => {
  return http.request<ResultProps<any>>("post", "/device/updDeviceStatus", {
    data
  });
};

export const deviceLockRecord = (data?: object) => {
  return http.requestJson<ResultProps<any>>("post", "/device/lockRecord", {
    data
  });
};

export interface FaultRecordProp {
  id: number;
  deviceId: string;
  deviceType: string;
  businessId: number;
  storeId: number;
  groupId: number;
  province: string;
  city: string;
  code: string;
  desc: string;
  handleStatus: number;
  faultTimeMillisecond: number;
}

export const faultRecordGetList = (data?: object) => {
  return http.requestJson<ResultProps<FaultRecordProp[]>>(
    "post",
    "/faultRecord/getList",
    {
      data
    }
  );
};

export interface faultRecordUpdProp {
  /**
   * 处理状态 0-未处理 1-已处理
   */
  handleStatus: number;
  /**
   * 自增ID
   */
  id: number;
}

export const faultRecordUpd = (data?: faultRecordUpdProp) => {
  return http.requestJson<ResultProps<null>>("post", "/faultRecord/upd", {
    data
  });
};
